package controller

import (
	"encoding/json"
	"fmt"
	"net/http"
	"time"

	"eve.com/eam/pm/service"
)

// **http.ResponseWriter, &
// 带有指针符号
func QueryProductHandler(res http.ResponseWriter, req *http.Request) {
	fmt.Println(req.Body)
	name := "桑塔纳"
	products := service.Query(name)
	// 对象转换为json
	products_str, err := json.Marshal(products)
	if err != nil {
		fmt.Println(err)
		panic(err)
	}
	fmt.Fprintf(res, string(products_str))
}

func CreateProductHandler(res http.ResponseWriter, req *http.Request) {
	product := service.Product{
		Name:        "桑塔纳",
		Code:        "S100",
		Create_date: time.Now(),
	}
	service.Insert(&product)
}
